﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SharpDepend.Datatypes
{
    public struct Vector2
    {
        private static Vector2 zero = new Vector2(0f, 0f);

        public static readonly Vector2 One = new Vector2(1, 1);

        public static readonly Vector2 Zero = new Vector2(0, 0);

        public double X;

        public double Y;

        public Vector2(double x, double y)
        {
            X = x;
            Y = y;
        }

        public override string ToString()
        {
            return "X: " + X + ", Y: " + Y;
        }

        public static Vector2 operator -(Vector2 left, Vector2 right)
        {
            return new Vector2(left.X - right.X, left.Y - right.Y);
        }

        public static Vector2 operator /(Vector2 left, Vector2 right)
        {
            return new Vector2(left.X / right.X, left.Y / right.Y);
        }

        public static Vector2 operator /(Vector2 left, double right)
        {
            return new Vector2(left.X / right, left.Y / right);
        }

        public static Vector2 operator *(Vector2 left, Vector2 right)
        {
            return new Vector2(left.X * right.X, left.Y * right.Y);
        }

        public static Vector2 operator *(Vector2 left, double right)
        {
            return new Vector2(left.X * right, left.Y * right);
        }

        public static Vector2 operator +(Vector2 left, Vector2 right)
        {
            return new Vector2(left.X + right.X, left.Y + right.Y);
        }

        public static double Dot(Vector2 vector1, Vector2 vector2)
        {
            return vector1.X * vector2.X + vector1.Y * vector2.Y ;
        }

        public static void Dot(ref Vector2 vector1, ref Vector2 vector2, out double result)
        {
            result = vector1.X * vector2.X + vector1.Y * vector2.Y;
        }

        public double LengthSquared()
        {
            double result;
            DistanceSquared(ref this, ref zero, out result);
            return result;
        }

        public static void DistanceSquared(ref Vector2 value1, ref Vector2 value2, out double result)
        {
            result = (value1.X - value2.X) * (value1.X - value2.X) +
                     (value1.Y - value2.Y) * (value1.Y - value2.Y);
        }

        public static double DistanceBetween(Vector2 point1, Vector2 point2)
        {
            return Math.Sqrt((point1.X - point2.X) * (point1.X - point2.X) + (point1.Y - point2.Y) * (point1.Y - point2.Y));
        }
    }
}
